package com.njtoyo.taxi.admin.repository.master;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.njtoyo.taxi.admin.library.Const;
import com.njtoyo.netrides.entity.Company;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

@DS(Const.PRIMARY_DS)
public interface CompanyRepository extends JpaRepository<Company, Integer> {

    @Query(value = "SELECT DISTINCT id FROM company WHERE canton_id IN (:cantonIds)", nativeQuery = true)
    List<Long> findCompanyIdsByCantonIds(@Param("cantonIds") List<Long> cantonIds);

    @Query(value = "SELECT DISTINCT canton_id FROM company WHERE id IN (:companyIds)", nativeQuery = true)
    List<Long> findCantonIdsByCompanyIds(@Param("companyIds") List<Long> companyIds);
}
